﻿using AjaxControlToolkit;
using ASP;
using IPMS.AccessAuth;
using System;
using System.Globalization;
using System.Threading;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using SysOperationLayer.DBHandle;
using SysComm;


public partial class Login : Page, IRequiresSessionState
{
    LogDB m_logdb = new LogDB();
    protected override void InitializeCulture()
    {
        if (base.Request.Form["__EVENTTARGET"] == "lbEng")
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
            this.Session["Culture"] = "en-US";
        }
        else if (base.Request.Form["__EVENTTARGET"] == "lbTradChi")
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("zh-TW");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-TW");
            this.Session["Culture"] = "zh-TW";
        }
        else if (base.Request.Form["__EVENTTARGET"] == "lbSimpChi")
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("zh-CN");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN");
            this.Session["Culture"] = "zh-CN";
        }

        if (Session["Culture"] != null)
        {
            if (Session["Culture"].ToString() == "en-US")
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
            }
            else if (Session["Culture"].ToString() == "zh-TW")
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("zh-TW");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-TW");
            }
            else if (Session["Culture"].ToString() == "zh-CN")
            {
                Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("zh-CN");
                Thread.CurrentThread.CurrentUICulture = new CultureInfo("zh-CN");
            }
        }
        else
        {
            Thread.CurrentThread.CurrentCulture = CultureInfo.CreateSpecificCulture("en-US");
            Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
            this.Session["Culture"] = "en-US";
            
        }
        base.InitializeCulture();
    }

    protected void Login1_LoggedIn(object sender, EventArgs e)
    {
        string OwnerGroupId;
        bool SuperUser;
        Auth getUserId = new Auth(string.Empty, this.Login1.UserName, string.Empty);
        this.Session["UserId"] = getUserId.GetUserId().ToString();
        string UserId = this.Session["UserId"].ToString();
        int intRet = 0;
        int AlertDay = 0;
        intRet = new Auth(UserId, string.Empty, "Default").GetUserInfo(out OwnerGroupId, out SuperUser, out AlertDay);
        this.Session["OwnerGroupID"] = OwnerGroupId.ToString();
        this.Session["SuperUser"] = SuperUser;
        this.Session["UserName"] = this.Login1.UserName;
        this.Session["AlertDay"] = AlertDay;

        m_logdb.writeSucLog(SysUtil.m_functiong_login, "login ipms system succeed!");
    }
    

    protected void Page_Load(object sender, EventArgs e)
    {
        //if (!this.Page.IsPostBack)
        //{
        //    this.Session["Culture"] = "en-US";
        //}
    }
    protected void Login1_LoginError(object sender, EventArgs e)
    {
        m_logdb.writeLog(SysUtil.m_functiong_login, "", "", "", "login ipms system faile!,username:" + this.Login1.UserName, "FAILE", Request.UserHostAddress.ToString(), DateTime.Now.ToString());
    }
}

